from die import Die
import pygal

# 创建一个骰子
die1 = Die(6)
die2 = Die(6)

# 掷几次骰子，并将结果存于列表中
results = []
for i in range(1000):
    result = die1.roll() + die2.roll()
    results.append(result)

# 分析结果 统计6个面出现的次数
frequencies = []
for value in range(2, die1.num_sides + die2.num_sides + 1):
    frequency = results.count(value)  # 计数
    frequencies.append(frequency)

# 对结果进行可视化 柱状图
hist = pygal.Bar()
hist.title = "Results of rolling one D6 1000 times."
hist.x_labels = ['2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']  # x坐标
hist.x_title = "Result"
hist.y_title = "Frequency of Result"

hist.add('D6 + D6', frequencies)
# 将这个图表渲染为一个SVG 文件,这种文件的扩展名必须为.svg。
hist.render_to_file('dice_visual.svg')

